import javax.swing.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class StudentGUI extends JFrame {

	static JTextField firstNameTextField;
	static JTextField lastNameTextField;
	static JTextField ageTextField;
	static JTextField ssnTextField;
	static JTextField studentIDTextField;
	static JTextField gpaTextField;
	static JTextField advisorTextField;

	public StudentGUI() {
		setLayout(new GridLayout(8, 2, 5, 5));
		setTitle("Student");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(300,300);
		
		add(new JLabel(" First Name: "));
		firstNameTextField = new JTextField();
		add(firstNameTextField);
		
		add(new JLabel(" Last Name: "));
		lastNameTextField = new JTextField();
		add(lastNameTextField);
		
		add(new JLabel(" Age: "));
		ageTextField = new JTextField();
		add(ageTextField);
		
		add(new JLabel(" SSN: "));
		ssnTextField = new JTextField();
		add(ssnTextField);
		
		add(new JLabel(" Student ID: "));
		studentIDTextField = new JTextField();
		add(studentIDTextField);
		
		add(new JLabel(" G.P.A.: "));
		gpaTextField = new JTextField();
		add(gpaTextField);
		
		add(new JLabel(" Advisor: "));
		advisorTextField = new JTextField();
		add(advisorTextField);
		
		JButton submit = new JButton("Submit");
		add(submit);
		StudentSubmitListener listener1 = new StudentSubmitListener();
		submit.addActionListener(listener1);
		
		
		JButton cancel = new JButton("Cancel");
		cancel.addActionListener(new StudentCancelListener());
		add(cancel);
	}
}

class StudentSubmitListener implements ActionListener {
	@Override
	public void actionPerformed(ActionEvent e) {
		Student s;
		int age = Integer.parseInt(StudentGUI.ageTextField.getText());
		float gpa = Float.parseFloat(StudentGUI.gpaTextField.getText());
	    s = new Student(StudentGUI.firstNameTextField.getText(), StudentGUI.lastNameTextField.getText(), age, 
	    		StudentGUI.ssnTextField.getText(), StudentGUI.studentIDTextField.getText(), gpa, StudentGUI.advisorTextField.getText());
	    System.out.println(s.toString());
	    Main.chooserframe.setVisible(true);
		Main.studentframe.setVisible(false);
		StudentGUI.firstNameTextField.setText("");
		StudentGUI.lastNameTextField.setText(""); 
		StudentGUI.ageTextField.setText(""); 
		StudentGUI.ssnTextField.setText("");
		StudentGUI.gpaTextField.setText("");
		StudentGUI.studentIDTextField.setText("");
		StudentGUI.advisorTextField.setText("");
	}
}

class StudentCancelListener implements ActionListener {
	@Override
	public void actionPerformed(ActionEvent e) {
		Main.chooserframe.setVisible(true);
		Main.studentframe.setVisible(false);
		StudentGUI.firstNameTextField.setText("");
		StudentGUI.lastNameTextField.setText(""); 
		StudentGUI.ageTextField.setText(""); 
		StudentGUI.ssnTextField.setText("");
		StudentGUI.gpaTextField.setText("");
		StudentGUI.studentIDTextField.setText("");
		StudentGUI.advisorTextField.setText("");
	}
}
